<?php

namespace App\Models\Admin;

use Illuminate\Notifications\Notifiable;

use Illuminate\Foundation\Auth\User as Authenticatable;
              
use Zizaco\Entrust\Traits\EntrustUserTrait;

class Admin extends Authenticatable
{   
    /**
     * 与roles表建立联系
     *
     * @var array
     * roles()、hasRole($name)、can($permission)
     * ability($roles,$permissions,$options)
     */
    use Notifiable, EntrustUserTrait;

    protected $table = 'admins';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function giveRolesTo(array $RolesId){
        $this->detachRoles();
        $this->attachRoleToId($RolesId);
    }

    public function attachRoleToId($RolesId)
    {
        foreach ($RolesId as $pid) {
            $this->attachRole($pid);
        }
    }
}
